﻿<template>
  <l-layout>
    <l-panel>
      <div class="l-rblock l-form-viewer" style="padding:8px;">
        <el-form :model="formData" :rules="rules" size="mini" labelPosition="left" labelWidth="80px" ref="form">
          <div class="l-auto-window only-tabs">
            <el-tabs v-model="activeName" type="card">
              <el-tab-pane class="l-tabs-container" :label="$t('新增采购申请单')" name="tab0">
                <el-row :gutter="5">
                  <div class="l-rblock">
                    <el-col v-if="lr_formLookAuth('f_PurchaseNo')" :span="8">
                      <el-form-item :label="$t('单据编码')" prop="f_PurchaseNo">
                        <el-input v-model="formData.f_PurchaseNo" :placeholder="$t('请输入')"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col v-if="lr_formLookAuth('f_Theme')" :span="8">
                      <el-form-item :label="$t('主题')" prop="f_Theme" :required="true">
                        <el-input v-model="formData.f_Theme" :placeholder="$t('请输入')">
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col v-if="lr_formLookAuth('f_PurchaseType')" :span="8">
                      <el-form-item :label="$t('采购类别')" prop="f_PurchaseType" :required="true">
                        <l-select :options="f_PurchaseTypeOptions" v-model="formData.f_PurchaseType"></l-select>
                      </el-form-item>
                    </el-col>
                    <el-col v-if="lr_formLookAuth('f_ApplyDate')" :span="8">
                      <el-form-item :label="$t('申请日期')" prop="f_ApplyDate" :required="true">
                        <l-date format="yyyy-MM-dd HH:mm:ss" dateType="datetime" :clearable="true"
                          v-model="formData.f_ApplyDate" :placeholder="$t('请选择')">
                        </l-date>
                      </el-form-item>
                    </el-col>
                    <el-col v-if="lr_formLookAuth('f_Appler')" :span="8">
                      <el-form-item :label="$t('申请人')" prop="f_Appler">
                        <l-user-select v-model="formData.f_Appler"></l-user-select>
                      </el-form-item>
                    </el-col>
                    <el-col v-if="lr_formLookAuth('f_Department')" :span="8">
                      <el-form-item :label="$t('申请单位')" prop="f_Department">
                        <l-company-select v-model="formData.f_Department"></l-company-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <div>
                        <el-alert :title="$t('识别说明')" type="info" :description="$t(
                          '本案例请上传图片格式的发票信息'
                        )
                          " show-icon :closable="false">
                        </el-alert>
                      </div>
                    </el-col>
                    <el-col v-if="lr_formLookAuth('f_File')" :span="24">
                      <el-form-item :label="$t('附件上传')" prop="f_File" style="margin-top: 14px;">
                        <l-upload v-model="formData.f_File">
                        </l-upload>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item labelWidth="80px">
                        <el-button size="small" :plain="false" :round="false" :circle="false" icon="" type="warning"
                          @click="handleOcrRead">附件识别</el-button>
                      </el-form-item>
                    </el-col>
                    <el-col v-if="lr_formLookAuth('f_Description')" :span="24">
                      <el-form-item :label="$t('备注信息')" prop="f_Description">
                        <el-input type="textarea" :rows="25" v-model="formData.f_Description" :placeholder="$t('请输入')">
                        </el-input>
                      </el-form-item>
                    </el-col>
                  </div>
                </el-row>
              </el-tab-pane>

            </el-tabs>
          </div>
        </el-form>
      </div>
    </l-panel>

  </l-layout>
</template>
<script>
const api = window.$api.demo.ocrDemo;
export default {
  data() {
    return {
      activeName: 'tab0',
      formData: {
        f_PurchaseNo: "", // 单据编码
        f_Theme: "", // 主题
        f_PurchaseType: "", // 采购类别
        f_ApplyDate: "", // 申请日期
        f_Appler: "", // 申请人
        f_Department: "", // 申请单位
        f_File: "", // 附件上传
        f_Description: "", // 备注
        f_ModifyDate: "", // 修改时间
        f_ModifyUserName: "", // 修改人员

      },
      rules: {
        f_PurchaseNo: [
          { required: true, message: '请输入单据编码' }
        ],
        f_Theme: [
          { required: true, message: '请输入主题' }
        ],
        f_PurchaseType: [
          { required: true, message: '请选择采购类别' }
        ],
        f_ApplyDate: [
          { required: true, message: '请选择申请日期' }
        ]
      },
      lr_erp_productinfo_columns: [
        { id: 'lr_erp_productinfo_F_Code', prop: 'f_Code', label: '商品编号' },
        { id: 'lr_erp_productinfo_F_Name', prop: 'f_Name', label: '商品名称' },
        { id: 'lr_erp_productinfo_F_BarCode', prop: 'f_BarCode', label: '条码' },
        { id: 'lr_erp_productinfo_F_Place', prop: 'f_Place', label: '产地' },
        { id: 'lr_erp_productinfo_F_Specification', prop: 'f_Specification', label: '规格' },
        { id: 'lr_erp_productinfo_F_Type', prop: 'f_Type', label: '型号' },
        { id: 'lr_erp_productinfo_F_Number', prop: 'f_Number', label: '批次号' },
        { id: 'lr_erp_productinfo_F_Unit', prop: 'f_Unit', label: '单位' },
        { id: 'lr_erp_productinfo_F_Count', prop: 'f_Count', label: '数量' },
        { id: 'lr_erp_productinfo_F_Price', prop: 'f_Price', label: '单价' },
        { id: 'lr_erp_productinfo_F_Amount', prop: 'f_Amount', label: '金额' },
      ],
      lr_erp_productinfo_data: [],

    };
  },
  computed: {
    f_PurchaseTypeOptions() {
      return [{ "value": "2", "label": "新闻类" }, { "value": "3", "label": "产品类" }, { "value": "4", "label": "信息类" }]
    },
  },
  mounted() {
  },
  methods: {
    handleLr_erp_productinfoAddRow() {
      let point = {}
      point.f_Code = ""
      point.f_Name = ""
      point.f_BarCode = ""
      point.f_Place = ""
      point.f_Specification = ""
      point.f_Type = ""
      point.f_Number = ""
      point.f_Unit = ""
      point.f_Count = ""
      point.f_Price = ""
      point.f_Amount = ""
      this.lr_erp_productinfo_data.push(point)
    },
    handleLr_erp_productinfoDeleteRow(event) {
      this.lr_erp_productinfo_data.splice(event.index, 1)
    },

    // 重置表单
    resetForm() {
      this.formData.f_Id = ''
      this.lr_erp_productinfo_data = []
      this.$formClear(this.$refs.form)
    },
    // 校验表单
    validateForm() {
      return new Promise((resolve) => {
        this.$refs.form.validate((valid) => {
          if (valid) {
            if (!this.$refs.lr_erp_productinfo_table.validate()) {
              resolve(false)
              return
            }
            resolve(true)
          }
          else {
            resolve(false)
          }
        })
      })

    },
    // 设置表单数据
    setForm(data) {
      this.formData = this.$deepClone(data.erp_purchase_applyEntity)
      this.lr_erp_productinfo_data = data.erp_productList
    },
    // 获取表单数据
    getForm() {
      let formData = {}
      formData.erp_purchase_applyEntity = {}
      formData.erp_purchase_applyEntity.f_PurchaseNo = this.formData.f_PurchaseNo // 单据编码
      formData.erp_purchase_applyEntity.f_Theme = this.formData.f_Theme // 主题
      formData.erp_purchase_applyEntity.f_PurchaseType = this.formData.f_PurchaseType // 采购类别
      formData.erp_purchase_applyEntity.f_ApplyDate = this.formData.f_ApplyDate // 申请日期
      formData.erp_purchase_applyEntity.f_Appler = this.formData.f_Appler // 申请人
      formData.erp_purchase_applyEntity.f_Department = this.formData.f_Department // 申请单位
      formData.erp_purchase_applyEntity.f_File = this.formData.f_File // 附件上传
      formData.erp_purchase_applyEntity.f_Description = this.formData.f_Description // 备注
      formData.erp_productList = this.lr_erp_productinfo_data
      return formData
    },
    //Ocr识别
    async handleOcrRead() {
      const res = await this.$awaitWraper(api.orcread(this.formData.f_File))
      if (res) {
        this.formData.f_Description = res
      }
    }
  }
}
</script>